﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using doufu.Common;
using doufu.Model;

namespace doufu.WebUI.Controllers
{
    public class StoryController : BaseController
    {
        //
        // GET: /Story/

        public ActionResult Index()
        {
            return View();
        }

        [UserAuthorize]
        public ActionResult Add(int? id)
        {
            var entity = id.HasValue ? Services.Story.Detail(id.Value) : new story();
            Title = entity.story_title;
            return View(entity);
        }

        [HttpPost]
        [ValidateInput(false)]
        public ActionResult Add(story entity)
        {
            if (ModelState.IsValid)
            {
                Title = entity.story_title;
                Services.Story.Save(entity, this);
                return RedirectToAction("Index", "Home");
            }
            return View(entity);
        }

        //[OutputCache(Duration = 600)]
        public ActionResult Details(Guid? id)
        {
            var entity = new story();
            if (id.HasValue)
            {
                entity = Services.Story.Detail(id.Value);
            }
            if (entity == null)
            {
                entity = new story();
            }
            Title = entity.story_title;
            return View(entity);
        }

    }
}
